<? 
	include('base.php');
	User::protect();
	$section = 'band_news';
	include_class('band_news');
	include_class('band_members');
	$db = new db;
	
	if ($_POST['submit']) { 
		// add news entry
		$bn = BandNews::add($_POST);
		if (!db::isError($bn)) {
			header('Location: band_news_edit.php?id=' . $bn->getID());
		}
	}	
	$calendar = true;
	$editors = array('description', 'body');
	$page_title = 'Add/Edit Band News';

	include('layout/header.php');
?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_news.php">Band News&nbsp;&#62;</a>&nbsp;Add News Entry
</div>

<? 

$uo = User::getCurrent();
$bm = BandMember::getByUserID($uo->getID());
if (!db::isError($bm)) {
	$bmFirstName = $uo->getFirstName();
}


if (!BandNews::canAdd()) {
	Error::outputDialog('Return to Band News','band_news.php','You are not an administrator, and you are not a band member. Therefore, you cannot add band news.');
} else {

	if (db::isError($bn)) {
		$bn->outputList();
	}
	
	?>
		<h1>add entry:</h1>
		<div class="inset">
		<form id="edit_entry" action="<?=$PHP_SELF?>?task=add" method="post">
		<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
		<tr>
			<td colspan="3" valign="top">
			<strong>Headline</strong><br/>
			<input type="text" value="<?=$_POST['title']?>" class="text" name="title">
			</td>
		</tr>
		<tr>
			<td width="33%"><strong>Poster</strong><br/>		
			<? if (User::isAdmin()) { ?>
				<select name="user_id">
					<?
					$ul = new UserList();
					$uArray = $ul->getActiveAdminUsers();
					foreach ($uArray as $uo) { ?>
						<option class="admin-user" value="<?=$uo->getID()?>"<? if ($_POST['user_id'] == $uo->getID()) { ?> SELECTED<? } ?>><?=$uo->getFirstName()?></option>
					<? }
					
					$bmlist = new BandMemberList();
					$bmarray = $bmlist->get_active_band_members();
					foreach ($bmarray as $bm) {
						$uo = $bm->getUserObject();
					?>
						<option value="<?=$uo->getID()?>"<? if ($_POST['user_id'] == $uo->getID()) { ?> SELECTED<? } ?>><?=$uo->getFirstName()?></option>
					<? } ?>
				</select>
	
			<? } else { 
				$uo = User::getCurrent();
				echo($uo->getFirstName());
			} ?>
			
			</td>
			<td width="34%" valign="top">
			
			<?
			
			$date = ($_POST) ? $_POST['date'] : db::get_local_datetime(DATE_FORMAT);
			$time = ($_POST) ? $_POST['time'] : db::get_local_datetime(TIME_FORMAT);
		
			?>
			<strong>Date (<a style="vertical-align: middle" href="javascript:void(0)" onclick="popUpCalendar(this, document.getElementById('date'), 'm/dd/yyyy')">Calendar</a>)</strong><br/>
			<input name="date" id="date" class="text" type="text" value="<?=$date?>">
			
			</td>
			<td width="33%" valign="top">
						
			<strong>Time</strong><br/>
			<input name="time" id="time" class="text" type="text" value="<?=$time?>">
			</td>
	
		</tr>
		</table>
		<div class="edit-form">
		<strong>Description</strong><br/>
		<textarea name="description" id="description" class="mid"><?=$_POST['description']?></textarea>
		</div>
		<div class="edit-form">
		<strong>Body</strong><br/>
		<textarea name="body" id="body" class="full"><?=$_POST['body']?></textarea>
		</div>
		
		<input type="submit" value="Add Entry" name="submit" class="button">
		<input type="submit" class="button" value="Exit Without Updating" name="preview" onclick="location.href='band_news.php'; return false" class="button">
		</form>
		</div>
<? } ?>

<? include('layout/footer.php'); ?>
